<?php
class TooltipController extends Zend_Controller_Action
{
	static $_default_Table = 'sales';
  
	public function init()
	{
		IndexController::initAdmin($this);
	}
		
	public function indexAction()
	{	
    
  //  var_dump($this->AppUI);
    if(PriviledgeController::checkPriviledge(1, "G0003", "F0009", $this->AppUI->country)==false)
    {
        
    }
  
		$strType	= $this->_request->getParam('strType', self::$_default_Table);
		$arrResult	= QTooltip::search($this->AppUI->country, $strType);
		
		$this->view->strType	= $strType;
		$this->view->arrResult	= $arrResult;
	}
	
	public function addAction()
	{	
		//post METHOD	
		if($this->_request->isPost())
		{
			$strColumn			= $this->_request->getParam('strColumn', null);
			$strNameShow		= $this->_request->getParam('strNameShow', null);
			$strDesription		= $this->_request->getParam('strDescription', null);
			$strDataValidate	= $this->_request->getParam('strDataValidate', null);
			$strType			= $this->_request->getParam('strType', null);
			$intId				= $this->_request->getParam('intId', null);
			
			if($intId	=="")
			{
				$intId = "0";
			}
			
			$arrInfo		= QTooltip::get_by_id($intId,  $this->AppUI->country);
			$this->view->arrayType = QTooltip::get_column($this->AppUI->country ."_".$strType ,$this->AppUI->country);
			$this->view->strType = $strType;		
			
			if($strColumn !="" && $strType !="" && $intId =="0")
			{
				$arrParams	= array
					(
						'column'			=> $strColumn,
						'name_show'			=> $strNameShow,
						'description'		=> $strDesription,
						'data_validate'		=> $strDataValidate,
						'type'				=> $this->AppUI->country ."_". $strType,
						);
				QTooltip::insert($arrParams, $this->AppUI->country);
				echo '<script>parent.submit_done()</script>';
			}
			else
			{				
				$arrParams		= array
					(
						'id'				=> $intId,
						'name_show'			=> $strNameShow,
						'column'			=> $strColumn,
						'description'		=> $strDesription,
						'data_validate'		=> $strDataValidate,
						'type'				=> $this->AppUI->country ."_". $strType,
						);
				QTooltip::update($arrParams, $this->AppUI->country);
				echo '<script>parent.submit_done()</script>';
			}
			exit;
		}
		
		//get METHOD
		$intId			= $this->_request->getParam('intId', null);
		$strType		= $this->_request->getParam('strType', null);
		$strColumn		= $this->_request->getParam('strColumn', null);
		
		if ($strType=="")
		{
			$strType = $this->AppUI->country."_".self::$_default_Table;
		}
		else
		{
			$strType = $this->AppUI->country. "_". $strType;
		}
		
		if($intId	=="")
		{
			$intId = "0";
		}
		
		$arrResult	=	QTooltip::get_by_id($intId,  $this->AppUI->country);
		if(count($arrResult) > 0)
		{
			$this->view->arrResult			=	$arrResult;
			$this->view->strType			=	$arrResult["type"];	
			$this->view->strColumn			=	$arrResult["column"];	
			$this->view->strNameShow		=	$arrResult["name_show"];		
			$this->view->strDescription		=	$arrResult["description"];	
			$this->view->strDataValidate	=	$arrResult["data_validate"];	
			$this->view->intId = $arrResult["id"];
		}
		else
		{
			$this->view->strType = $strType;	
			$this->view->strColumn = $strColumn;	
			
			$arrResult	=	QTooltip::get_by_coumn_type( $strColumn, $strType,  $this->AppUI->country);
			$this->view->strDescription =	$arrResult["description"];	
			$this->view->intId = $arrResult["id"];
		}
		
		$this->view->country = $this->AppUI->country;
		$this->view->arrayType = QTooltip::get_column($this->view->strType, $this->AppUI->country);
	}
}
?>
